//
//  BdjmmCell.m
//  Together
//
//  Created by Dawn on 12-12-15.
//  Copyright (c) 2012年 Dawn. All rights reserved.
//

#import "BdjmmCell.h"

@implementation BdjmmCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        
        // 性别
        sexImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 5, 10, 10)];
        sexImageView.image = [UIImage imageNamed:@"nv.png"];
        [self addSubview:sexImageView];
        [sexImageView release];
        
        // 姓名
        nameLbl = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, SCREEN_WIDTH/2 - 10, 20)];
        nameLbl.font = [UIFont systemFontOfSize:14.0f];
        nameLbl.textColor = [UIColor colorWithRed:57.0/255.0f green:70.0f/255.0f blue:83.0/255.0f alpha:1.0];
        [self addSubview:nameLbl];
        [nameLbl setBackgroundColor:[UIColor clearColor]];
        [nameLbl release];
        
        // 发布日期
        timeLbl = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH/2, 0, SCREEN_WIDTH/2 - 10, 20)];
        timeLbl.font = [UIFont systemFontOfSize:12.0f];
        timeLbl.textColor = [UIColor colorWithRed:244.0/255.0f green:137.0f/255.0f blue:13.0/255.0f alpha:1.0];
        timeLbl.textAlignment = UITextAlignmentRight;
        [timeLbl setBackgroundColor:[UIColor clearColor]];
        [self addSubview:timeLbl];
        [timeLbl release];
        
        // 气泡背景
        textContentView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 20, SCREEN_WIDTH, 10)];
        textContentView.image = [[UIImage imageNamed:@"bubble.png"] stretchableImageWithLeftCapWidth:25 topCapHeight:15];
        [self addSubview:textContentView];
        
        [textContentView release];
        
        // 内容
        textLbl = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, textContentView.bounds.size.width - 20, 20)];
        textLbl.font = [UIFont systemFontOfSize:14.0f];
        textLbl.textColor = [UIColor colorWithRed:66.0/255.0f green:66.0/255.0f blue:66.0/255.0f alpha:1.0];
        textLbl.lineBreakMode = UILineBreakModeWordWrap;
        textLbl.numberOfLines = 0;
        
        [textLbl setBackgroundColor:[UIColor clearColor]];
        [textContentView addSubview:textLbl];
        [textLbl release];
    }
    return self;
}

- (void) setName:(NSString *)name{
    [nameLbl setText:name];
    float x = (name.length - 1) * 5 + 28;
    sexImageView.frame = CGRectMake(x, 5, 10, 10);
}

- (void) setTime:(NSString *)time{
    [timeLbl setText:time];
}

- (void) setSex:(NSString *)sex{
    if ([sex isEqualToString:@"男|"]) {
        [sexImageView setImage:[UIImage imageNamed:@"nan.png"]];
    }else{
        [sexImageView setImage:[UIImage imageNamed:@"nv.png"]];
    }
    
}

- (void) setContent:(NSString *)text{
    CGSize size = CGSizeMake(textLbl.frame.size.width, 10000);
    size = [text sizeWithFont:[UIFont systemFontOfSize:14.0f] constrainedToSize:size lineBreakMode:UILineBreakModeWordWrap];
    textLbl.frame = CGRectMake(textLbl.frame.origin.x, textLbl.frame.origin.y, textLbl.frame.size.width, size.height + 10);
    textContentView.frame = CGRectMake(textContentView.frame.origin.x, textContentView.frame.origin.y, textContentView.frame.size.width, textLbl.frame.size.height + 20);
    
    [textLbl setText:text];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
